package top.hkyzf.study.j2se.collection;

/**
 * @author 朱峰
 * @date 2021-4-9 15:11
 */
public class User implements Comparable{
    private String name;
    private Integer age;
    private Mydate mydate;

    public User() {
    }

    public User(String name, Integer age, Mydate mydate) {
        this.name = name;
        this.age = age;
        this.mydate = mydate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Mydate getMydate() {
        return mydate;
    }

    public void setMydate(Mydate mydate) {
        this.mydate = mydate;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", mydate=" + mydate +
                '}';
    }

    @Override
    public int compareTo(Object o) {
        if(o instanceof User) {
            User user = (User) o;
            return this.name.compareTo(user.name);
        }
        throw new RuntimeException();
    }
}


class Mydate implements Comparable<Mydate>{
    private Integer year;
    private Integer month;
    private Integer day;

    public Mydate() {
    }

    public Mydate(Integer year, Integer month, Integer day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public Integer getDay() {
        return day;
    }

    public void setDay(Integer day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "Mydate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }

    @Override
    public int compareTo(Mydate o) {

        int year = this.getYear() - o.getYear();
        if(year != 0) {
            return year;
        }
        int month = this.getMonth() - o.getMonth();
        if(month != 0) {
            return month;
        }
        return this.getDay() - o.getDay();
    }
}